﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Finance.Querys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;

namespace mozhi.smarterp.Finance.Accounts
{
    [RemoteService]
    [Route("api/v1/accounts/balances")]
    public class AccountBalanceController : BaseController
    {
        private IAccountBalanceAppService _appService;

        public AccountBalanceController(IAccountBalanceAppService appService)
        {
            this._appService = appService;
        }

        [HttpGet]
        [Route("initialization")]
        public async Task<List<AccountBalanceDto>> GetAllAsync(string keyword)
        {
            var result = await _appService.FindAsync(new AccountBalanceQuery() { Keyword = keyword, IsInitalize = true, IncludeDimension = false , AllAccount=true });

            return result;
        }

        [HttpGet]
        [Route("initialization/{accountId}")]
        public async Task<AccountBalanceDto> GetAsync(Guid accountId, string keyword)
        {
            var query = new AccountBalanceQuery() { Keyword = keyword, IsInitalize = true, AccountIds = new List<Guid>() { accountId }};

            var result = await _appService.FindAsync(query);

            return result.FirstOrDefault();
        }

        [HttpPut]
        [Route("initialization")]
        public async Task<AccountBalanceDto> UpdateAsync(AccountBalanceUpdateDto dto)
        {
            var result = await _appService.UpdateAsync(dto);

            return result;
        }

        [HttpGet]
        [Route("initialization/trial")]
        public async Task<TrialBalanceResultDto> Trialbalance()
        {
            var result = await _appService.TrialBalance();

            return result;
        }

        [HttpDelete]
        [Route("initialization")]
        public async Task ClearAsync()
        {
            await _appService.ClearAsync();
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);
        }

        [HttpGet]
        [Route("count")]
        public async Task GetCountAsync(int? period)
        {
            await _appService.GetCountAsync(period);
        }
    }
}
